package ControllerLayer;
import java.util.*;
import ContainerLayer.*;

/**
 * Write a description of class OrderController here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class OrderController
{
    // instance variables - replace the example below with your own
    private OrderContainer oCon;
    private static OrderController instance; //singleton
    private CostumerController coCtr;
    private SalesmanController smCtr;
    //     private ProductController pCtr;
    private long id;

    /**
     * Constructor for objects of class OrderController
     */
    private OrderController()
    {
        // initialise instance variables
        oCon = OrderContainer.getInstance();
        smCtr = SalesmanController.getInstance();
        coCtr = CostumerController.getInstance();
        //         pCtr = ProductController.getInstance();
    }

    public long getID()
    {
        return id;
    }

    public static OrderController getInstance()
    {
        if(instance == null)
        {
            instance = new OrderController();
        }
        return instance;
    }

    public void createOrder(boolean done, long costumerName, long salesmanName)
    {
        id++;
        String date = getDateAndtime();
        String dateModify = null;

        Costumer costumer = coCtr.readCostumer(costumerName);
        Salesman salesman = smCtr.readSalesman(salesmanName);

        Order o = new Order(id, date, dateModify, done, costumer, salesman);
        oCon.addOrder(o);

    }

    public String getDateAndtime()
    {       
        Date date = new Date();
        return date.toString();
    }

    public Order readOrder(long id)
    {
        return oCon.readOrder(id);
    }

    public void updateOrder(long id, boolean done, long costumerName, long salesmanName)
    {
        String dateModify = getDateAndtime();

        Costumer costumer = coCtr.readCostumer(costumerName);
        Salesman salesman = smCtr.readSalesman(salesmanName);        

        oCon.updateOrder(id, dateModify, done, costumer, salesman);
    }

    public void deleteOrder(long id)
    {
        oCon.deleteOrder(id);
    }

    public void printAllOrder()
    {
        oCon.printOutAllOrder();
    }

    public void printOneOrder(long id)
    {
        oCon.printOneOrder(id);
    }

    public void createPartOrder(long orderID, long pd, long pn)
    {
        oCon.createPartOrder(orderID, pd, pn);
    }

    public PartOrder readPartOrder(long orderID, long partID)
    {
        return oCon.readPartOrder(orderID, partID);
    }

    public void updatePartOrder(long orderID, long partID, long pd, long pn)
    {
        oCon.updatePartOrder(orderID, partID, pd, pn);
    }

    public void deletePartOrder(long orderID, long partID)
    {
        oCon.deletePartOrder(orderID, partID);
    }

    public void printOnePartOrderID(long orderID, long partID)
    {
        oCon.printOnePartOrderID(orderID, partID);
    }

    public void printAllPartOrder()
    {
        oCon.printOutAllOrder();
    }

}